<%--
  Created by IntelliJ IDEA.
  User: 联想
  Date: 2020/3/6
  Time: 20:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>学生重置密码</title>

    <!-- Custom fonts for this template-->
    <link href="${pageContext.request.contextPath}/static/stuLogin/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="${pageContext.request.contextPath}/static/stuLogin/css/sb-admin-2.min.css" rel="stylesheet">

</head>
<script src="/js/jquery-3.3.1.js"></script>

<script>
    /*
        表单校验：
            1.用户名为学号：单词字符，长度9位
            2.密码：单词字符，长度8到20位
            3.email：邮件格式
            4.姓名：非空
            5.验证码：非空
     */

    //校验密码
    function checkPassword() {
        //1.获取密码值
        var password = $("#studentPwd").val();
        //2.定义正则
        var reg_password = /^\w{8,20}$/;

        //3.判断，给出提示信息
        var flag = reg_password.test(password);
        if(flag){
            //密码合法
            $("#studentPwd").css("border","2px solid green");
            $("#PwdSpan").css("color","green")
            $("#PwdSpan").html("符合要求");
        }else{
            //密码非法,加一个红色边框
            $("#studentPwd").css("border","2px solid red");
            $("#PwdSpan").css("color","red")
            $("#PwdSpan").html("请输入8-20长度的密码");
        }

        return flag;
    }

    function checkPassword2() {
        //1.获取密码值
        var password = $("#studentPwd").val();
        var password2 = $("#studentPwd2").val();
        if(password2===''){
            $("#studentPwd2").css("border","2px solid red");
            $("#Pwd2Span").css("color","red");
            $("#Pwd2Span").html("请确认密码");
            return false;
        }
        if(password === password2){
            //密码一致
            $("#studentPwd2").css("border","2px solid green");
            return true;
        }else{
            //密码不一致
            $("#studentPwd2").css("border","2px solid red");
            $("#Pwd2Span").css("color","red");
            $("#Pwd2Span").html("密码不一致");
            return false;
        }

    }


    $(function () {
        //当表单提交时，调用所有的校验方法
        $("#rePwdForm").submit(function(){
            //1.发送数据到服务器
            if(checkPassword() && checkPassword2()){
                //校验通过,发送ajax请求，提交表单的数据   username=zhangsan&password=123
                return true;
            }
            //2.不让页面跳转
            return false;
            //如果这个方法没有返回值，或者返回为true，则表单提交，如果返回为false，则表单不提交
        });

        //当某一个组件失去焦点是，调用对应的校验方法
        $("#studentPwd").blur(checkPassword);
        $("#studentPwd2").blur(checkPassword2);
    });


</script>

<body class="bg-gradient-primary">

<div class="container">

    <!-- Outer Row -->
    <div class="row justify-content-center">

        <div class="col-xl-10 col-lg-12 col-md-9">

            <div class="card o-hidden border-0 shadow-lg my-5">
                <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="row">
                        <div class="col-lg-6 d-none d-lg-block bg-password-image"></div>
                        <div class="col-lg-6">
                            <div class="p-5">
                                <div class="text-center">
                                    <h1 class="h4 text-gray-900 mb-2">${student.studentName}(${student.studentNo})Reset Your Password</h1>
                                    <p class="mb-4">We have successfully verified your identity. Please complete the form to complete your password change.</p>
                                </div>
                                <form class="user" action="${pageContext.request.contextPath}/student/changePwd" method="get" id="rePwdForm">
                                    <input type="hidden" id="studentCode" name="studentCode" value="${student.studentCode}">
                                    <div class="form-group">
                                        <input type="password" class="form-control form-control-user" id="studentPwd" name="studentPwd" aria-describedby="emailHelp" placeholder="密码">
                                        <span id="PwdSpan"></span>
                                        <span id="NoSpan"></span>
                                    </div>
                                    <div class="form-group">
                                        <input type="password" class="form-control form-control-user" id="studentPwd2" name="studentPwd2" aria-describedby="emailHelp" placeholder="确认密码">
                                        <span id="Pwd2Span"></span>
                                    </div>
                                    <button type="submit" class="btn btn-primary btn-user btn-block">
                                        Reset Password
                                    </button>
                                </form>
                                <hr>
                                <div class="text-center">
                                    <a class="small" href="#"><span style="color:red;">${changeErrorMsg}</span>
                                        <span style="color:red;">${changeRightMsg}</span></a>
                                </div>
                                <div class="text-center">
                                    <a class="small" href="${pageContext.request.contextPath}/student/goLogin">Already have an account? Login!</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>

</div>

<!-- Bootstrap core JavaScript-->
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="${pageContext.request.contextPath}/static/stuLogin/js/sb-admin-2.min.js"></script>

</body>

</html>
